package com.goods.controller;

import com.goods.service.goodsService;
import com.goods.entity.goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/goods")
public class goodsController {

    @Autowired
    goodsService service;

    @RequestMapping("/")
    public String test()
    {
        return "商品服务----";
    }
    @RequestMapping("/add/{sid}")
    public String add(@PathVariable("sid") Integer sid)
    {
        goods g = new goods();
        g.setSid(sid);
        g.setName("手机");
        g.setPrice("5000");
        g.setStatus("已上架");
        g.setStorage("800");
        service.create(g);
        return "添加商品成功";
    }
    @RequestMapping("/find/{id}")
    public goods findOne(@PathVariable("id") Integer id)
    {
        return service.findOne(id);
    }

    @RequestMapping("/find")
    public List<goods> findAll()
    {
        return service.findAll();
    }


}
